﻿function showProductName(obj){
	var urls="supplierProduct!getProductBySupplierID.action?sId="+obj.value;		
	$.ajax({
			type: "get",
			cache:false,
			url: urls,
			dataType:'json',
			success:function(data){
				if(data!=null&&data!=''){
					///var str ='产品：<select name="product_num" id="product_num">';
					var str ='<option value="0">所有</option>';
					for(var i=0;i<data.length;i++){
						var gf = data[i];
						if(gf!=null&&gf!=''){
							str +='<option value='+gf.product_num+'>'+gf.product_name+'</option>';
						}				
					}
				//	str += '</select>';
					$('#product_num').empty();
					$('#product_num').html(str);
				}
			}
		});
}
function showChannelProject(obj){
	var urls="channelProject!getProjByChunnelNum.action?sId="+obj.value;
	$.ajax({
			type: "get",
			cache:false,
			url: urls,
			dataType:'json',
			success:function(data){
			//alert(data);
				if(data!=null&&data!=''){
					var str ='<option value="0">--- 所有 ---</option>';
					for(var i=0;i<data.length;i++){
						var gf = data[i];
						if(gf!=null&&gf!=''){
							str +="<option value='"+gf.project_num+"'>"+gf.project_name+"</option>";
						}				
					}
					$('#project_num').empty();
					$('#project_num').html(str);
				}
			}
	});
}
function showSms(obj)
{
	var urls="smsCharge!getSmsByChunnelNum.action?sId="+obj.value;	
		$.ajax({
				type: "get",
				cache:false,
				url: urls,
				dataType:'json',
				success:function(data){
				//alert(data);
					if(data!=null&&data!=''){
					///	var str ='短信计费：<select name="fee_num" id="fee_num">';
						var str ='<option value="0">--- 请选择通道指令 ---</option>';
						for(var i=0;i<data.length;i++){
							var gf = data[i];
							if(gf!=null&&gf!=''){
								str +="<option value='"+(gf.command_title+gf.sms_num)+"'>"+gf.command_title+" -> "+gf.sms_num+"</option>";
							}				
						}
						///str += '</select>';
						$('#fee_num').empty();
						$('#fee_num').html(str);
					}
				}
	});
}

function showcount(){
	
	var start=$("#startDate").val()
	var end=$("#endDate").val();
	var phone=$("#phone").val();
	var supplier_num=$("#supplier_num").val();
	var product_num=$("#product_num").val();
	var channel_num=$("#channel_num").val();
	var project_num=$("#project_num").val();
	var chunnel_num=$("#chunnel_num").val();
	var fee_num=$("#fee_num").val();
	var area=$("#area").val();
	
	var isphone=0;
	var issupp=0;
	var ischannel=0;
	var ischunnel=0;
	var isarea=0;
	var isproduct=0;
	var isdate=0;
	if(document.getElementById("isphone").checked){ isphone=1; }
	if(document.getElementById("ischannel").checked){ ischannel=1; }
	if(document.getElementById("ischunnel").checked){ ischunnel=1; }
	if(document.getElementById("isarea").checked){ isarea=1; }
	if(document.getElementById("issupp").checked){ issupp=1; }
	if(document.getElementById("isproduct").checked){ isphone=1; }
	if(document.getElementById("isdate").checked){ isdate=1; }
	
	///alert("isdate= " + $("#isdate").val());
    var parm="?start="+start+"&end="+end+"&supplier_num="+supplier_num+"&product_num="+product_num;
   		parm=parm+"&phone="+phone+"&fee_num="+fee_num+"&area="+encodeURI(area)+"&channel_num="+channel_num+"&chunnel_num="+chunnel_num;
   		parm=parm+"&ischannel="+ischannel+"&isphone="+isphone+"&isproduct="+isproduct;
   		parm=parm+"&isdate="+isdate+"&isarea="+isarea+"&issupp="+issupp+"&ischunnel="+ischunnel;
   	var urls="sell!getDetail.action"+parm;
   	$.ajax({
		type: "get",
		cache:false,
		url: urls,
		dataType:'json',
		success:function(data){
		
		var str="<div class='title_info'>";
		if(data!=null&&data.length>0)
		{
			if("1"!=isphone&&"1"!=issupp&&"1"!=ischannel&&"1"!=ischunnel&&"1"!=isarea&&"1"!=isproduct&&"1"!=isdate)
			{
				
				str=str+"<ul><li style='width:99%; text-align:left;'> 总和 </li></ul></div><div class='focuedetail'>";
				str=str+"<ul><li style='width:99%; text-align:left;'> "+data[0].count+" </li></ul></div>";
			}else
			{
				var count=data.length;
			 	str=str+"<ul><li style='width:15%;'>日期</li>";
				str=str+"<li style='width:15%;'>渠道商</li>";
				str=str+"<li style='width:15%;'>提供商</li>";
				str=str+"<li style='width:14%;'>应用</li>";
				str=str+"<li style='width:10%;'>通道号</li>";
				str=str+"<li style='width:10%;'>地区</li>";
				str=str+"<li style='width:10%;'>手机号</li>";			
				str=str+"<li style='width:10%;'>发送数</li></ul></div><div class='focuedetail'>";	
				for(var index=0;index<count;index++){
				
					var times=data[index].date;
					if(times.length>16)
					{
						times=times.substring(0,16);
					}
					str=str+"<ul>";
				 	str=str+"<li style='width:15%;'>"+data[index].date+"</li>";
					str=str+"<li style='width:15%;'>"+data[index].channel_num+"</li>";
					str=str+"<li style='width:15%;'>"+data[index].supplier_num+"</li>";
					str=str+"<li style='width:14%;'>"+data[index].product_num+"</li>";
					str=str+"<li style='width:10%;'>"+data[index].chunnel_num+"</li>";
					str=str+"<li style='width:10%;'>"+data[index].area+"</li>";
					str=str+"<li style='width:10%;'>"+data[index].mobile_phone+"</li>";
					str=str+"<li style='width:10%;'>"+data[index].count+"</li></ul>";
				}
			}
		}else
	   	{
	   		str=str+"<ul><li style='width:100%;'>没有数据.....</li></ul>";
	   	}
	   	str=str+"</div>";
	   //	alert(str);
	   	jQuery("#DataContext").empty();
		jQuery("#DataContext").append(str);
	
	  }
   }); 
}


/**请求数据*/		
function showdata(pagenow,pagesize){   
	var start=$("#startDate").val()
	var end=$("#endDate").val();
	var phone=$("#phone").val();
	var supplier_num=$("#supplier_num").val();
	var product_num=$("#product_num").val();
	var channel_num=$("#channel_num").val();
	var project_num=$("#project_num").val();
	var chunnel_num=$("#chunnel_num").val();
	var fee_num=$("#fee_num").val();
	var area=$("#area").val();
	

	var parm="?start="+start+"&end="+end+"&supplier_num="+supplier_num+"&product_num="+product_num;
   		parm=parm+"&phone="+phone+"&fee_num="+fee_num+"&area="+encodeURI(area);
   		parm=parm+"&channel_num="+channel_num+"&project_num="+project_num;
   		parm=parm+"&pagenow="+pagenow+"&pagesize="+pagesize+"&chunnel_num="+chunnel_num;
   		
   	var urls="sell!showDetail.action"+parm;	
   	$.ajax({
		type: "get",
		cache:false,
		url: urls,
		dataType:'json',
		success:function(data){
		
		var str="<div class='title_info'>";
		if(data!=null&&data!='')
		{
			
			var count=data.length;
		 	str=str+"<ul><li style='width:15%;'>imsi卡号</li>";
			str=str+"<li style='width:15%;'>手机号</li>";
			str=str+"<li style='width:10%;'>指令头</li>";
			str=str+"<li style='width:10%;'>地区</li>";
			str=str+"<li style='width:10%;'>平台号</li>";
			str=str+"<li style='width:15%;'>发送时间</li>";
			str=str+"<li style='width:24%;'>内容</li></ul></div><div class='focuedetail'>";	
			for(var index=0;index<count;index++){
			
				var times=data[index].date;
				if(times.length>16)
				{
					times=times.substring(0,16);
				}
				str=str+"<ul>";
			 	str=str+"<li style='width:15%;'>"+data[index].charge_num+"</li>";
				str=str+"<li style='width:15%;'>"+data[index].mobile_phone+"</li>";
				str=str+"<li style='width:10%;'>"+data[index].fee_num+"</li>";
				str=str+"<li style='width:10%;'>"+data[index].area+"</li>";
				str=str+"<li style='width:10%;'>"+data[index].parent_channel+"</li>";
				str=str+"<li style='width:15%;'>"+times+"</li>";
				str=str+"<li style='width:24%;'>"+data[index].project_num+"</li></ul>";
			}
	
		}else
	   	{
	   		str=str+"<ul><li style='width:100%;'>没有数据.....</li></ul>";
	   	}
	   	str=str+"</div>";
	   	jQuery("#DataContext").empty();
		jQuery("#DataContext").append(str);
	}    
   }); 	
   urls="sell!showCountDetail.action"+parm;	
	 	$.ajax({
		type: "get",
		cache:false,
		url: urls,
		dataType:'json',
		success:function(data){
		var tt="";
		if(data!=null&&data!='')
		{
		 	tt=data.jwebpage;	
		    
		 }
		// alert(str);
	    jQuery("#pager").empty();
	    jQuery("#pager").append(tt);
	   	}
	});	 						   		
} 
function test()
{
	var isphone=0;
	var issupp=0;
	var ischannel=0;
	var ischunnel=0;
	var isarea=0;
	var isproduct=0;
	var isdate=0;
	if(document.getElementById("isphone").checked){ isphone=1; }
	if(document.getElementById("ischannel").checked){ ischannel=1; }
	if(document.getElementById("ischunnel").checked){ ischunnel=1; }
	if(document.getElementById("isarea").checked){ isarea=1; }
	if(document.getElementById("issupp").checked){ issupp=1; }
	if(document.getElementById("isproduct").checked){ isphone=1; }
	if(document.getElementById("isdate").checked){ isdate=1; }
	if(isphone==0&&issupp==0&&ischannel==0&&ischunnel==0&&isarea==0&&isproduct==0&&isdate==0)
	{
		alert("至少要选中一个分组项才能导出Excel文件");
		return false;
	}
	return true;
}